package com.punch.system.controller;


import com.punch.common.dto.system.BannerDTO;
import com.punch.common.model.Result;
import com.punch.common.page.PageInfo;
import com.punch.common.query.syste.BannerQueryInfo;
import com.punch.common.vo.system.BannerVO;
import com.punch.system.service.BannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * banner管理 前端控制器
 * </p>
 *
 * @author wjj
 * @since 2020-12-14
 */
@RestController
@Api(value = "BannerController", tags = "banner管理Controller")
public class BannerController {

    @Resource
    private BannerService bannerService;

    /**
     * banner列表
     *
     * @param queryInfo 查询条件
     * @return PageInfo<BannerVO>
     */
    @GetMapping(value = "/banners", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "banner列表", notes = "banner列表", produces = "application/json")
    public Result<PageInfo<BannerVO>> listBanner(@ModelAttribute BannerQueryInfo queryInfo) {
        return Result.succeed(bannerService.listBanner(queryInfo));
    }


    /**
     * 保存banner
     *
     * @param bannerDTO 提交表单
     * @return id
     */
    @PostMapping(value = "/banner", produces = "application/json; charset=utf-8")
    @ApiOperation(value = " 保存banner", notes = " 保存banner", produces = "application/json")
    public Result<Integer> saveBanner(@RequestBody BannerDTO bannerDTO) {
        return Result.succeed(bannerService.saveBanner(bannerDTO));
    }

    /**
     * 修改banner
     *
     * @param bannerDTO 提交表单
     * @return id
     */
    @PutMapping(value = "/banner", produces = "application/json; charset=utf-8")
    @ApiOperation(value = " 修改banner", notes = " 修改banner", produces = "application/json")
    public Result<Integer> updateBanner(@RequestBody BannerDTO bannerDTO) {
        return Result.succeed(bannerService.updateBanner(bannerDTO));
    }


    /**
     * banner详情
     *
     * @param bannerId bannerId
     * @return BannerVO
     */
    @GetMapping(value = "/banner/{bannerId}", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "banner详情", notes = "banner详情", produces = "application/json")
    public Result<BannerVO> getBanner(@PathVariable Integer bannerId) {
        return Result.succeed(bannerService.getBanner(bannerId));
    }

    /**
     * 删除banner
     *
     * @param bannerId bannerId
     * @return id
     */
    @DeleteMapping(value = "/banner/{bannerId}", produces = "application/json; charset=utf-8")
    @ApiOperation(value = " 删除banner", notes = " 删除banner", produces = "application/json")
    public Result<Integer> deleteBanner(@PathVariable Integer bannerId) {
        return Result.succeed(bannerService.deleteBanner(bannerId));
    }


    /**
     * 修改banner状态
     *
     * @param bannerId bannerId
     * @param status   状态 0-不显示 1-显示
     * @return bannerId
     */
    @PutMapping(value = "/banner/{bannerId}/status/{status}", produces = "application/json; charset=utf-8")
    @ApiOperation(value = " 修改banner状态", notes = " 修改banner状态", produces = "application/json")
    public Result<Integer> updateBannerStatus(@PathVariable Integer bannerId, @PathVariable Integer status) {
        return Result.succeed(bannerService.updateBannerStatus(bannerId, status));
    }
}
